package com.uppfind.framework.core.dao.mybatis.meta;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 数据库表Table元数据
 * Created by xuliugen on 2017/7/3.
 */
public class TableMetaData {

    //表名称
    protected String name = null;

    //表别名,如果指定了别名,查询结果将使用别名进行封装
    protected String alias = null;

    //备注
    protected String comment = null;

    /**
     * 表字段:key为property，value为ColumnMetaData
     */
    protected Map<String, ColumnMetaData> columnMetaDataMap = new LinkedHashMap<>();
    protected Map<String, ColumnMetaData> aliasColumnMetaDataMap = new LinkedHashMap<>();

    /**
     * 为TableMetaData添加ColumnMetaData
     * @param columnMetaData
     * @return
     */
    public TableMetaData addColumn(ColumnMetaData columnMetaData) {
        columnMetaData.setTableMetaData(this);
        columnMetaDataMap.put(columnMetaData.getProperty(), columnMetaData);
        if (!columnMetaData.getName().equals(columnMetaData.getAlias())) {
            aliasColumnMetaDataMap.put(columnMetaData.getAlias(), columnMetaData);
        }
        return this;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Map<String, ColumnMetaData> getColumnMetaDataMap() {
        return columnMetaDataMap;
    }

    public void setColumnMetaDataMap(Map<String, ColumnMetaData> columnMetaDataMap) {
        this.columnMetaDataMap = columnMetaDataMap;
    }

    public Map<String, ColumnMetaData> getAliasColumnMetaDataMap() {
        return aliasColumnMetaDataMap;
    }

    public void setAliasColumnMetaDataMap(Map<String, ColumnMetaData> aliasColumnMetaDataMap) {
        this.aliasColumnMetaDataMap = aliasColumnMetaDataMap;
    }
}
